package org.opencare.plugins.model;

import java.io.IOException;
import java.net.URL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.rosaloves.net.shorturl.bitly.Bitly;
import com.rosaloves.net.shorturl.bitly.BitlyException;
import com.rosaloves.net.shorturl.bitly.BitlyFactory;

public class BitLyImpl {
	/** Logger for this class and subclasses */
	protected final Log logger = LogFactory.getLog(getClass());
	
	private Bitly bitly;

	public BitLyImpl(String username, String apiKey) {
		super();
		// TODO Auto-generated constructor stub
		//bitly = BitlyFactory.newJmpInstance(username,apiKey);
		bitly = BitlyFactory.newInstance(username,apiKey);
	
	}

	public String shorten(String url) {

		URL sUrl = null;
		
		try {
			sUrl = bitly.shorten(url).getShortUrl();
		} catch (BitlyException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return sUrl.toString();
	}
}
